package com.dbh.alg.algorithm.recursion;

/**
 * 递归冒泡排序
 *
 * @author 董帮辉
 * @date 2025/4/19
 **/
public class E04BubbleSort {

    public static void sort(int[] arr) {
        bubble(arr, arr.length - 1);
    }

    private static void bubble(int[] arr, int j) {
        if (j == 0) {
            return;
        }
        int x = 0;
        for (int i = 0; i < j; i++) {
            if (arr[i] > arr[i + 1]) {
                int t = arr[i];
                arr[i] = arr[i + 1];
                arr[i + 1] = t;
                x = i;
            }
        }
        bubble(arr, x);
    }

}
